/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
 * MAIN
 */

import gov.nasa.worldwind.awt.AWTInputHandler;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.examples.ApplicationTemplate;

import Tuio.TuioClient;
//import gov.nasa.worldwind.*;

import gov.nasa.worldwind.view.BasicOrbitView;

/**
 *
 * @author Taha Bintahir
 */
public class WWTouchStart extends ApplicationTemplate {

	public static class AppFrame extends ApplicationTemplate.AppFrame {
		//initialise application
		public AppFrame() //constructor
		{
			//control JWW UI i.e. what to display and what not to display
			//super ( statusBar, LayerPanel, statsPanel)
			super(true, false, false);

			/* LayerList layers = this.getWwd().getModel().getLayers();
			 for (Layer layer : layers)
			 {
			 if(layer instanceof VirtualEarthLayer || layer instanceof MercatorTiledImageLayer)
			 layer.setEnabled(false);
			 }*/
			// Update layer panel
			//  this.getLayerPanel().update(this.getWwd());

			try {

				//initialise WorldWindow (globe)
				WorldWindowGLCanvas wwd = this.getWwd();

				//Setup JWW view
				BasicOrbitView bov = new BasicOrbitView(((BasicOrbitView) wwd.getView()).getOrbitViewModel());
				wwd.setView(bov);

				//initialise touch handler TUIO
				((AWTInputHandler) wwd.getInputHandler()).removeHoverSelectListener();
				wwd.getInputHandler().setEventSource(null);

				WWTouchInputHandler wwtih = new WWTouchInputHandler();
				wwtih.setEventSource(wwd);
				wwtih.setLayerPanel(getLayerPanel());
				wwd.setInputHandler(wwtih);

				//Setup TUIO Communication handler
				final int port = 3333;
				TuioClient tClient = new TuioClient(port);
				System.out.println("listening to TUIO messages at port " + port);
				tClient.addTuioListener(wwtih);
				tClient.connect();

				wwtih.setSmoothViewChanges(false); // FALSE makes the view fast/choppy!!

				// End of View ==========================================

			}
			// throw excetion if TUIO is not initialsied
			catch (Exception e) {
				e.printStackTrace();
			}
		} // AppFrame constructor
	} // AppFrame class

	//Application Title 
	public static void main(String[] args) {
		ApplicationTemplate.start("TouchWorldWind", AppFrame.class);
	}

}